package org.adream.account.rest.api;

import javax.servlet.http.HttpServletRequest;

import org.adream.account.entity.IntegralRuleEntity;
import org.adream.account.model.ResultModel;
import org.adream.account.service.IntegralRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("integralRule")
@Controller
public class IntegralRuleApiController {
	
	@Autowired
	IntegralRuleService integralRuleService;
	
	/**
	 *  获取积分规则
	 * @return
	 */
	@RequestMapping(value = "getIntegralRule", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> getIntegralRule() {
		IntegralRuleEntity entity = integralRuleService.getIntegralRule();
		return new ResultModel<IntegralRuleEntity>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, entity);
	}
	
	/**
	 * 	保存积分规则  （add or update）
	 * @return
	 */
	@RequestMapping(value = "saveIntegralRule", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<?> saveIntegralRule(HttpServletRequest request,@RequestBody IntegralRuleEntity entity) {
		integralRuleService.saveIntegralRule(entity,request);
		return new ResultModel<String>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, null);
	}
}